
#include <glib.h>
#include <stdlib.h>
#include "hlfs.h"


typedef struct {
//const gchar * dirpath;
}Fixture;

static void
test_init_hlfs(Fixture *fixture,const void * data){
    const char* uri= "local:///xx";
    const char* fs_name= "name";
    //struct hlfs_ctrl * hlfs_ctrl=init_lhdfs(uri,fs_name);
    //g_assert(hlfs_ctrl!=NULL);
}


static void hlfs_init_setup(Fixture *fixture, const void *data){
    const gchar *test_env_path = (const gchar*)data;
    g_print("test env path :%s\n",test_env_path);
    //g_remove(test_env_path);
    //g_assert(g_mkdir(test_env_path,0700) == 0);
    char *fs_dir = g_build_filename(test_env_path,"testfs",NULL);
    g_assert(g_mkdir(fs_dir,0700) == 0);
    GKeyFile *  sb_keyfile= g_key_file_new();
    g_key_file_set_string(sb_keyfile,"METADATA","fs_name","testfs");
    g_key_file_set_integer(sb_keyfile,"METADATA","block_size",8196);
    g_key_file_set_integer(sb_keyfile,"METADATA","segment_size",100000);
    gchar *content = g_key_file_to_data(sb_keyfile,NULL,NULL);
    char *sb_file_path = g_build_filename(fs_dir,"superblock",NULL);
    g_print("sb file path %s\n",sb_file_path);
    GError *error = NULL;
    if( TRUE != g_file_set_contents(sb_file_path,content,strlen(content),&error)){
         g_print("-----error message %s\n",error->message);
         error=NULL;
    }
    g_key_file_free(sb_keyfile);
    g_free(sb_file_path);
    g_free(fs_dir);
}

static void hlfs_init_teardown(Fixture *fixture,const void *data){
   const gchar *test_env_path = (const gchar*)data;
   g_print("clean ... dir path :%s\n",test_env_path);
   char *fs_dir = g_build_filename(test_env_path,"testfs",NULL);
   char *sb_file = g_build_filename(fs_dir,"superblock",NULL);
   g_assert(g_remove(sb_file)==0);
   g_assert(g_remove(fs_dir)==0);
   g_free(fs_dir);
   g_free(sb_file);
}



int
main (int   argc,
        char *argv[])
{
    g_test_init (&argc, &argv, NULL);
    //g_test_add_func ("/misc/init_lhdfs",test_init_lhdfs);
    g_test_add ("/misc/init_lhdfs",Fixture,g_get_current_dir(),hlfs_init_setup, test_init_hlfs, hlfs_init_teardown);
    return g_test_run();
}


